package com.zhj.jvm.test.ref;

import java.lang.ref.WeakReference;

/**
 * @author zhj
 */
public class WeakReferenceDemo {
    public static void main(String[] args) throws InterruptedException {
        // 装饰模式
        WeakReference<Object> weakRef = new WeakReference<>(new Object());
        System.out.println(weakRef.get() == null ? "已被回收":"没被回收");
        System.gc(); // 建议gc执行一次回收（存在概率）
        System.out.println(weakRef.get() == null ? "已被回收":"没被回收");
    }
}
